import Taro from "@tarojs/taro";
import { cloneDeep } from "lodash";
import { FabricJSON, GoodsData } from "types/type";

// 跳转设计器的方法
export default async function toDesign({
    productId,//商品id
    productNegativeId,//底板id
    productDesign,//具体商品设计json
    designName,
    size,//尺码
    color,//颜色名
    colorValue,//颜色值
    needupload = true,// 是否需要更新底板
}: {
    productId?: number,//商品id
    productNegativeId: number,//底板id
    productDesign?: GoodsData["productData"],//具体商品设计json
    designName: string,
    size: string,//规格
    color?: string//颜色
    colorValue?: `#${string}`,//颜色值
    needupload?: boolean// 是否需要更新设计器
}) {
    console.log(cloneDeep({
        productId,//商品id
        productNegativeId,//底板id
        productDesign,//具体商品设计json
        designName,
        size,//尺码
        color,//颜色
        colorValue,
        needupload,// 是否需要更新底板
    }));

    //判断登录
    // if (!userStore.isLogin) {
    //     Taro.navigateTo({ url: "/pages/login/index" });
    //     return;
    // }

    // 保存数据 /subpkg/editor/index" 页面会自动去读取

    // Taro.setStorageSync('designer_addimg', addimg);
    // Taro.setStorageSync('designer_template', template);

    Taro.setStorageSync('designer_productId', productId); //商品id
    Taro.setStorageSync('designer_productNegativeId', productNegativeId); //底板id
    Taro.setStorageSync('designer_productDesign', productDesign);
    Taro.setStorageSync('designer_name', designName);
    Taro.setStorageSync('designer_time', new Date().valueOf());
    Taro.setStorageSync('designer_size', size); // 规格
    Taro.setStorageSync('designer_color', color); // 颜色
    Taro.setStorageSync('designer_colorValue', colorValue); // 颜色值
    Taro.setStorageSync('designer_needupload', needupload); //是否需要更新设计器

    // 跳转
    return new Promise<void>((resolve, reject) => {
        Taro.navigateTo({
            url: "/subPages/Design/Design",
            success: () => {
                resolve();
            },
            fail: (err) => {
                resolve();
            }
        });
    });

}